package com.dems.admin.controller;

import com.dems.admin.security.SecurityUtils;
import com.dems.dao.dataobject.CfgDeviceInfo;
import com.dems.domain.DeviceInfoReqVO;
import com.dems.domain.JsonResponse;
import com.dems.service.CfgDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/deviceInfo")
public class CfgDeviceInfoController {

    @Autowired
    private CfgDeviceInfoService cfgDeviceInfoService;

    @PostMapping("/find")
    public JsonResponse findDeviceInfos(@RequestBody DeviceInfoReqVO deviceInfoReqVO){
        return JsonResponse.success(cfgDeviceInfoService.queryDeviceInfoList(deviceInfoReqVO));
    }

    @PostMapping("/batchCreate")
    public JsonResponse batchCreateDeviceInfo(@RequestBody List<CfgDeviceInfo> cfgDeviceInfo){
        return JsonResponse.success(cfgDeviceInfoService.batchCreateDeviceInfo(cfgDeviceInfo, SecurityUtils.getLoanassistUser()));
    }

    @PostMapping("/create")
    public JsonResponse createDeviceInfo(@RequestBody CfgDeviceInfo cfgDeviceInfo){
        return JsonResponse.success(cfgDeviceInfoService.createDeviceInfo(cfgDeviceInfo, SecurityUtils.getLoanassistUser()));
    }

    @PostMapping("/update")
    public JsonResponse updateDeviceInfo(@RequestBody CfgDeviceInfo cfgDeviceInfo){
        return JsonResponse.success(cfgDeviceInfoService.updateDeviceInfo(cfgDeviceInfo, SecurityUtils.getLoanassistUser()));
    }
}
